package com.zenith.user.service.impl;

import com.zenith.user.mapper.RolePermissionMapper;
import com.zenith.user.po.domain.RolePermission;
import com.zenith.user.po.dto.RolePermissionDTO;
import com.zenith.user.service.RolePermissionService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.zenith.common.result.PageResult;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.stereotype.Service;

/**
 * 角色权限关联 业务实现
 *
 * @author makejava
 * @since 2025-08-15
 */
@Service
public class RolePermissionServiceImpl extends ServiceImpl<RolePermissionMapper, RolePermission> implements RolePermissionService {

    @Override
    public PageResult<RolePermission> getRolePermissionPage(RolePermissionDTO query) {
        // 创建分页对象
        Page<RolePermission> page = new Page<>(query.getPageNum() != null ? query.getPageNum() : 1, 
                                             query.getPageSize() != null ? query.getPageSize() : 10);
        // 执行分页查询
        Page<RolePermission> pageResult = lambdaQuery().page(page);
        // 封装返回结果
        return PageResult.ofPage(page.getCurrent(), page.getSize(), pageResult.getTotal(), pageResult.getRecords());
    }
}
